﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JqueryProj.CssUtil.Model;
using System.Drawing;
using System.Web.UI.HtmlControls;

namespace JqueryProj.CssUtil
{
    public partial class FontSizeCalculation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<ModelFontSize> ftCol = new List<ModelFontSize>();

            for (decimal i = 8; i <= 48; i++)
            {
                ModelFontSize mod = new ModelFontSize();
                mod.Point = string.Format("{0}pt", ((i * 72) / 96).ToString("#.#"));
                mod.Pixel = string.Format("{0}px", i.ToString("#"));
                mod.Em =  string.Format("{0}em",(i / 16).ToString("0.###"));
                mod.Percent = string.Format("{0}%", ((i / 16) * 100).ToString("#.#"));
                
                ftCol.Add(mod);
            }

            rptFont.DataSource = ftCol;
            rptFont.DataBind();


            System.Array ret = Enum.GetValues(typeof(KnownColor));
            KnownColor[] allColors = new KnownColor[ret.Length];
            Array.Copy(ret, allColors, ret.Length);


            List<ModelColor> colorCollection = new List<ModelColor>();

            for (int i = 0; i < allColors.Length; i++)
            {
                ModelColor modcolor = new ModelColor();
                
                Color clr = Color.FromName(allColors[i].ToString());
                 //Response.Write(string.Format("{0}, R = {1} G = {2} B = {3}, <br />",clr.Name, clr.R, clr.G, clr.B));
                
               // Response.Write(ColorTranslator.ToHtml(clr) + "<br />");

                modcolor.ColorName = clr.Name;
                modcolor.Hex = String.Format("#{0:X2}{1:X2}{2:X2}", clr.R, clr.G, clr.B);
                modcolor.RGB = string.Format("{0},{1},{2}", clr.R, clr.G, clr.B);
                modcolor.Color = clr;
                colorCollection.Add(modcolor);

                //lblBrightness.Text = "Brightness = " + this.BackColor.GetBrightness().ToString();
                //lblHue.Text = "Hue = " + this.BackColor.GetHue().ToString();
                //lblSaturation.Text = "Saturation = " + this.BackColor.GetSaturation().ToString();



                //Response.Write(Color.FromArgb(clr.ToArgb).ToString());
                //string htmlHexColorValueThree = String.Format("#{0:X2}{1:X2}{2:X2}", clr.R, clr.G, clr.B);
                //Response.Write( string.Format("<div style=background-color:{0} ; color:{0}>{1}</div><br />",  htmlHexColorValueThree,clr.Name));
            }

            rptColor.DataSource = colorCollection;
            rptColor.DataBind();

            //http://www.xiirus.net/articles/article-c-convert-drawing_color-to-html-hex-color-value-and-back-cc8mp.aspx
        }

        protected void rptColor_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.DataItem != null)
            {
                ModelColor curItem = (ModelColor)e.Item.DataItem;

                HtmlGenericControl divColor = e.Item.FindControl("divColor") as HtmlGenericControl;
                HtmlTableCell tdColor = e.Item.FindControl("tdColor") as HtmlTableCell;

                divColor.Style.Add("background-color", curItem.Hex);
                //HtmlTableCelltdColor.Cells = curItem.Hex;
                
                

            }



        }

//        System.Drawing.Color c;
//foreach (string s in Enum.GetNames(typeof(System.Drawing.KnownColor)))
//{
//c = System.Drawing.Color.FromName(s);
//}
      
    }
}